#!/usr/bin/env ruby
# Copyright (C) 2003-2011 Wang Pengcheng <wpc0000@gmail.com>
# , released under the MIT license
# You may obtain a template of the MIT License at
# http://www.opensource.org/licenses/mit-license.php
$KCODE = 'utf8'

require 'socket'
require 'cgi'

HTTP_END  = '--*****--'

def handle_client(c)
  p 'New Request'
  data = ''
  while true
    input = c.gets          # Read a line of input from the client
    break if !input         # Exit if no more input
    data << input
    break if input.chop==HTTP_END
    c.flush                 # Force our output out
  end
  c.close                   # Close the client socket
end

server = TCPServer.open(8080)

while true
  client = server.accept
  Thread.start(client) do |c|
    handle_client(c)
  end
end

